<template>
  <a-popconfirm
    :title="title"
    @confirm="handleSubmit(userId)"
    okText="是"
    cancelText="否"
  >
    <a href="updateUserType">停用或启用</a>
  </a-popconfirm>
</template>

<script>
  import { updateUserType } from '@/api/basic/user'

  export default {
    name: 'UpdateUserType',
    props: {
      userId: {
        type: Number
      }
    },
    data () {
      return {
        title: '确定要停用或启用此用户吗？'
      }
    },
    watch: {
      userId: function () {
        this.title = '确定要停用或启用此用户吗？'
      }
    },
    methods: {
      handleSubmit (userId) {
        updateUserType({ 'userId': userId })
          .then(res => {
            if (res.message !== 'error') {
              this.$emit('ok')
            } else {
              this.$message.error('操作失败！')
            }
          })
      }
    }
  }
</script>
